<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="myUtil.materialCheck" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>person_save</title>
</head>
<body>
<%
    String itemId = request.getParameter("itemId");
    String itemName = request.getParameter("itemName");
    String itemClasses = request.getParameter("itemClasses");
    String vendorName = request.getParameter("vendorName");
    String site = request.getParameter("site");
    String inboundTime = request.getParameter("inboundTime");
    String contact = request.getParameter("contact");
    String phoneNumber = request.getParameter("phoneNumber");
    String itemDescription = request.getParameter("itemDescription");
    if (materialCheck.checkNumber(itemId) && materialCheck.checkS(itemName) && materialCheck.checkS(itemClasses) &&
            materialCheck.checkS(vendorName) && materialCheck.checkS(site) && materialCheck.checkS(inboundTime) &&
            materialCheck.checkS(contact) && materialCheck.checkPhoneNumber(phoneNumber)) {
        Connection conn = (Connection) session.getAttribute("Connection");
        String sql = "INSERT INTO material(itemId,itemName,itemClasses,vendorName,site,inboundTime,contact,phoneNumber,itemDescription)  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
//        String sql1 = "SELECT COUNT(*) AS num FROM material";
        //需要先获取到数据总量(设置id+1)
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
//        PreparedStatement preparedStatement1 = conn.prepareStatement(sql1);
//        ResultSet rs = preparedStatement1.executeQuery();
//        rs.next();
//        Integer id=Integer.parseInt(rs.getString("num"))+1;

        //设置参数信息
//        preparedStatement.setString(1, id.toString());
//        preparedStatement.setString(2, itemId);
//        preparedStatement.setString(3, itemName);
//        preparedStatement.setString(4, itemClasses);
//        preparedStatement.setString(5, vendorName);
//        preparedStatement.setString(6, site);
//        preparedStatement.setString(7, inboundTime);
//        preparedStatement.setString(8, contact);
//        preparedStatement.setString(9, phoneNumber);
//        preparedStatement.setString(10, itemDescription);

        preparedStatement.setString(1, itemId);
        preparedStatement.setString(2, itemName);
        preparedStatement.setString(3, itemClasses);
        preparedStatement.setString(4, vendorName);
        preparedStatement.setString(5, site);
        preparedStatement.setString(6, inboundTime);
        preparedStatement.setString(7, contact);
        preparedStatement.setString(8, phoneNumber);
        preparedStatement.setString(9, itemDescription);


        preparedStatement.executeUpdate();

        response.sendRedirect("material_list.jsp");
    } else {
        request.getRequestDispatcher("material_add.jsp").forward(request, response);
    }

%>
</body>
</html>
